package com.springcloud.util.model;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import static com.springcloud.util.model.NumberUtils.parseNumber;

/**
 * @Description: TODO
 * @Create by: 123
 * @Date: 2021/11/22 17:11
 */

@Data
public class Paddings {


    private float paddingTop;
    private float paddingRight;
    private float paddingBottom;
    private float paddingLeft;

    public Paddings(String paddings) {
        parse(paddings);
    }

    private void parse(String paddings) {
        if (StringUtils.isNotBlank(paddings)) {
            paddings = paddings.replace("[","").replace("]","");
            String[] strings = paddings.split(",");
            for (int i = 0; i < Math.min(strings.length, 4); i++) {
                if (i == 0) paddingTop = parseNumber(strings[0]);
                if (i == 1) paddingRight = parseNumber(strings[1]);
                if (i == 2) paddingBottom = parseNumber(strings[2]);
                if (i == 3) paddingLeft = parseNumber(strings[3]);
            }
        }
    }

}
